<template>
  <li class="todo-item">
    <input
      type="checkbox"
      :checked="done"
      @change="$emit('toggle', id, $event.target.checked)"
    />
    <span :class="{ done: done }">{{ content }}</span>
    <div class="buttons">
      <button @click="$emit('del', id)">删除</button>
    </div>
  </li>
</template>

<script setup>
defineProps({
  id: {
    type: String,
    required: true,
  },
  content: {
    type: String,
    required: true,
  },
  done: {
    type: Boolean,
    default: false,
  },
})

defineEmits(['toggle', 'edit', 'del'])
</script>

<style scoped>
.todo-item {
  display: flex;
  align-items: center;
  height: 40px;
  padding: 0 40px;
  list-style: none;
  border-bottom: 1px solid #eee;
}

.todo-item:hover {
  background-color: #f5f5f5;
}

.todo-item span {
  flex: 1;
  margin-left: 20px;
}

.todo-item .done {
  text-decoration: line-through;
  color: #999;
}

.todo-item .buttons button {
  margin-left: 5px;
  padding: 0 10px;
  height: 24px;
  border: none;
  border-radius: 3px;
  background-color: #ff6700;
  color: white;
  cursor: pointer;
}

.todo-item .buttons button:hover {
  opacity: 0.8;
}
</style>
